;
(function(win, doc, $) {

    var jsbk = win.JSBK || {};
    jsbk.Utils = {
        hostUrl: "http://192.168.0.18:8082",
        Toast:function(txt){
            var toastHtml = '<div class="tk_info" id="tkInfo"></div>';
            var toast = $(doc).find('body #tkInfo');
            if (toast.length) {
                toast.html(txt).show();
            }else{
                $(doc).find('body').append(toastHtml);
                $(doc).find('body #tkInfo').html(txt).show();
            }
            setTimeout(function(){
              $(doc).find('body #tkInfo').hide();
            },3000)
        },
        //取当前时间的前几个月的时间
        setMonth:function(n){
            var startTime = new Date();
                startTime.setMonth(startTime.getMonth()-n);
            var year = startTime.getFullYear();
            var month = startTime.getMonth()+1;
            if (month < 10) {month = '0'+month}
            var day = startTime.getDate()
            return year+'-'+month+'-'+day;
        },
         //检测登录
        checkLogin:function() {
            // {
            //     "message": "用户未登录",
            //     "status": "_9999" _0000   已登录
            // }
            var that = this;
            var status = "";
            $.ajax({
                url: this.hostUrl + '/checkLg.php',
                async: false,
                dataType: 'json',
                data: {
                    "cfrom": '159cai'
                },
                xhrFields: {
                    withCredentials: true
                },
                crossDomain: true,
                success: function(data) {
                    status = data.status;
                }
            });
            return status;
        },
        postAjax: function(d) {
            $.ajax({
                type: d.type || 'get',
                dataType: 'json',
                url: d.url ,
                data: d.data,
                xhrFields: {
                    withCredentials: true
                },
                crossDomain: true,
                traditional: true,
                beforeSend: function() {
                    d.beforeFun && d.beforeFun();
                },
                //请求成功时执行
                success: function(v) {
                    var code = v.code;
                    if (code == 200) {
                        // 正常处理
                        var data = v.data;
                        var mess = v.message
                        d.sucFun && d.sucFun(data);
                    } else if (code == -9999) { // 未登录
                        window.top.location.href = '/pages/examples/login.html'
                    } else {
                        // 异常处理
                        d.unusualFun && d.unusualFun(v);
                    }
                },
                complete: function(){
                    d.comFun && d.comFun();
                },
                //请求失败遇到异常触发
                error: function() {
                    d.errFun && d.errFun();
                }
            });
        },
        skin:function(){
            var skin = window.localStorage.getItem("skin")|| 'skin-blue';
            var skinColor = skin.split('-')[1];
            return {skin,skinColor}
        },
        GetQueryString: function(name) { //获取指定name的url参数
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
            var r = window.location.search.substr(1).match(reg);
            if (r != null) return (r[2]);
            return null;
        },

    };
    win.JSBK = jsbk;
})(window, document,window.jQuery);